package org.sixlab.googlecode;

import java.util.Random;

//random create 50 numbers between[10,50]
//then count how many times each number show
//print the number which show most and how many times it shows
//print the count result by the ascending order which the numbers shows
/**
 * 
 * @author HundredKG
 * 
 */
public class FindNum {
	static int	temp;

	public static void genNum(int[] a) {
		Random ran = new Random();
		for (int i = 0; i < a.length; i++) {
			a[i] = ran.nextInt(41) + 10;
		}
	}

	public static void printNumA(int[] a) {
		System.out.println("--start print A--");
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "\t");
			if (i % 10 == 9) {
				System.out.println();
			}
		}
		System.out.println("--end print A--");
	}

	public static void printNumB(int[][] b) {
		System.out.println("--start print B--");
		for (int j = 0; j < 41; j++) {
			System.out.print(b[0][j] + ":" + b[1][j] + "\t");
			if (j % 10 == 9) {
				System.out.println();
			}
		}
		System.out.println();
		System.out.println("--end print B--");
	}

	public static void countNum(int[] a, int[][] b) {
		for (int i = 0; i < a.length; i++) {
			if (i < 41) {
				b[0][i] = i + 10;
			}
			b[1][a[i] - 10]++;
		}
	}

	public static void sortNum(int[][] b) {
		for (int i = 0; i < b[1].length - 1; i++) {
			for (int j = 0; j < b[1].length - 1 - i; j++) {
				if (b[1][j] > b[1][j + 1]) {
					temp = b[0][j];
					b[0][j] = b[0][j + 1];
					b[0][j + 1] = temp;

					temp = b[1][j];
					b[1][j] = b[1][j + 1];
					b[1][j + 1] = temp;
				}
			}
		}
	}

	public static void printResult(int[][] b) {
		System.out.print("The most of the number:" + b[0][40]);
		for (int i = 39; i >= 0; i--) {
			if (b[1][40] == b[1][i]) {
				System.out.print("," + b[0][i]);
			}
			else {
				System.out.println();
				break;
			}
		}
		System.out.println("the times:" + b[1][40]);
		System.out.println("the count result:");
		for (int i = 0; i < b[1].length; i++) {
			if (b[1][i] != 0) {
				System.out.println("number: " + b[0][i] + " show " + b[1][i]
						+ " times.");
			}
		}
	}

	public static void main(String[] args) {
		int[] a = new int[50];
		int[][] b = new int[2][41];
		genNum(a);
		printNumA(a);
		countNum(a, b);
		printNumB(b);
		sortNum(b);
		printNumB(b);
		printResult(b);
	}

}
//--start print A--
//32      29      25      33      36      19      49      34      41      47
//32      34      41      27      47      27      37      25      35      49
//47      38      41      26      10      35      29      29      45      35
//25      38      46      15      25      11      46      23      39      49
//23      47      33      31      42      22      16      38      17      43
//--end print A--
//--start print B--
//10:1    11:1    12:0    13:0    14:0    15:1    16:1    17:1    18:0    19:1
//20:0    21:0    22:1    23:2    24:0    25:4    26:1    27:2    28:0    29:3
//30:0    31:1    32:2    33:2    34:2    35:3    36:1    37:1    38:3    39:1
//40:0    41:3    42:1    43:1    44:0    45:1    46:2    47:4    48:0    49:3
//50:0
//--end print B--
//--start print B--
//12:0    13:0    14:0    18:0    20:0    21:0    24:0    28:0    30:0    40:0
//44:0    48:0    50:0    10:1    11:1    15:1    16:1    17:1    19:1    22:1
//26:1    31:1    36:1    37:1    39:1    42:1    43:1    45:1    23:2    27:2
//32:2    33:2    34:2    46:2    29:3    35:3    38:3    41:3    49:3    25:4
//47:4
//--end print B--
//The most of the number:47,25
//the times:4
//the count result:
//number: 10 show 1 times.
//number: 11 show 1 times.
//number: 15 show 1 times.
//number: 16 show 1 times.
//number: 17 show 1 times.
//number: 19 show 1 times.
//number: 22 show 1 times.
//number: 26 show 1 times.
//number: 31 show 1 times.
//number: 36 show 1 times.
//number: 37 show 1 times.
//number: 39 show 1 times.
//number: 42 show 1 times.
//number: 43 show 1 times.
//number: 45 show 1 times.
//number: 23 show 2 times.
//number: 27 show 2 times.
//number: 32 show 2 times.
//number: 33 show 2 times.
//number: 34 show 2 times.
//number: 46 show 2 times.
//number: 29 show 3 times.
//number: 35 show 3 times.
//number: 38 show 3 times.
//number: 41 show 3 times.
//number: 49 show 3 times.
//number: 25 show 4 times.
//number: 47 show 4 times.
